/**
 * Copyright (c) 2009, Jim Hurne
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */
package org.tzconverter.util;

import java.awt.Image;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.swing.ImageIcon;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * Manages all of the icon resources for the application.
 *
 * @author Jim Hurne
 */
public class Icons {
  private static final Log logger = LogFactory.getLog(Icons.class);

  public static final String ICON_BASE_PATH = "/icons/nuvola/";

  private final ImageIcon error;
  private final ImageIcon load;
  private final ImageIcon save;
  private final ImageIcon reload;
  private final ImageIcon exit;
  private final ImageIcon top;
  private final ImageIcon translucent;
  private final ImageIcon settings;
  private final ImageIcon help;
  private final ImageIcon calc;
  private final ImageIcon remove;
  private final ImageIcon apply;  
  private final ImageIcon ok;
  private final ImageIcon cancel;
  
  private final List<Image> clocks;

  public Icons()
  {
    error = loadIcon("16x16/actions/no.png");
    load = loadIcon("16x16/actions/fileopen.png");
    save = loadIcon("16x16/actions/filesave.png");
    reload = loadIcon("16x16/actions/reload.png");
    exit = loadIcon("16x16/actions/exit.png");
    top = loadIcon("16x16/actions/top.png");
    translucent = loadIcon("16x16/actions/view_text.png");
    settings = loadIcon("16x16/actions/misc.png");
    help = loadIcon("16x16/actions/help.png");
    calc = loadIcon("22x22/apps/kcalc.png");
    remove = loadIcon("16x16/actions/cancel.png");
    apply = loadIcon("16x16/actions/button_ok.png");
    ok = apply;
    cancel = remove;
    
    //The clock icon is used as the application icon,
    //which is loaded in different sizes.  Some platforms
    //use different icon sizes in different contexts for the app.
    List<Image> clockImages = new ArrayList<Image>();
    clockImages.add(loadIcon("16x16/apps/clock.png").getImage());
    clockImages.add(loadIcon("22x22/apps/clock.png").getImage());
    clockImages.add(loadIcon("32x32/apps/clock.png").getImage());
    clockImages.add(loadIcon("48x48/apps/clock.png").getImage());
    clockImages.add(loadIcon("64x64/apps/clock.png").getImage());
    
    clocks = Collections.unmodifiableList(clockImages);
  }

  /**
   * Loads an icon by searching the classpath for the given path.
   * 
   * @param path
   * @return
   */
  public static ImageIcon loadIcon(String path)
  {
    String fullPath = ICON_BASE_PATH + path;
    logger.debug("Loading icon: [" + fullPath + "]");
    // ClassLoader loader = ClassLoader.getSystemClassLoader();
    URL url = Icons.class.getResource(fullPath);
    if (url != null)
    {
      return new ImageIcon(url);
    }
    logger.warn("Unable to find icon: [" + fullPath + "]");
    return null;
  }

  public ImageIcon getError()
  {
    return error;
  }

  public ImageIcon getLoad()
  {
    return load;
  }

  public ImageIcon getSave()
  {
    return save;
  }

  public ImageIcon getReload()
  {
    return reload;
  }

  public ImageIcon getExit()
  {
    return exit;
  }

  public ImageIcon getTop()
  {
    return top;
  }

  public ImageIcon getTranslucent()
  {
    return translucent;
  }

  public ImageIcon getSettings()
  {
    return settings;
  }

  public ImageIcon getHelp()
  {
    return help;
  }
  
  public ImageIcon getCalc()
  {
    return calc;
  }
  
  public ImageIcon getRemove()
  {
    return remove;
  }
  
  public ImageIcon getApply()
  {
    return apply;
  }

  public ImageIcon getOk()
  {
    return ok;
  }

  public ImageIcon getCancel()
  {
    return cancel;
  }

  public List<Image> getClocks()
  {
    return clocks;
  }
  
}
